package com.example.leetcode.stack_deque;

import java.util.Stack;

/**
 * 包含min函数的栈
 *
 * 思路：使用双栈，一个正常栈，一个min栈
 *
 */
public class MinStack {
    public static void main(String[] args) {

    }
    // 正常栈
    Stack<Integer> stack1 = new Stack<Integer>();
    // min栈
    Stack<Integer> stack2 = new Stack<Integer>();

    public void push(int node) {
        stack1.push(node);

        if (stack2.isEmpty() || stack2.peek() > node) {
            stack2.push(node);
        } else {
            // 最小值重复入min栈
            stack2.push(stack2.peek());
        }
    }

    public void pop() {
        stack1.pop();
        stack2.pop();
    }

    public int top() {
        return stack1.peek();
    }

    public int min() {
        return stack2.peek();
    }


}
